<?php 
defined('IN_TS') or die('Access Denied.');

switch($ts){

	case "":
	
		$cateid = intval($_GET['id']);


        $page = isset ( $_GET ['page'] ) ? intval ( $_GET ['page'] ) : 1;
        $url = tsUrl ( 'study', 'cate', array ('id'=>$cateid,'page' => ''));
        $lstart = $page * 40 - 40;

		
		$strCate = $new['study']->find('study_cates',array('cateid'=>$cateid));
	
		if($strCate['recateid']==0){
			
			//一级分类信息
			$oneCate = $strCate;
			
			//二级分类列表
			$arrTwoCate = $new['study']->findAll('study_cates',array(
				'recateid'=>$strCate['cateid'],
			));
			
			//条件 
			$where = array(
				'cateid'=>$strCate['cateid'],
				'isaudit'=>0,
			);
		
		}else{
			//一级分类信息
			$oneCate = $new['study']->find('study_cates',array(
				'cateid'=>$strCate['recateid']
			));
			//二级分类列表
			$arrTwoCate = $new['study']->findAll('study_cates',array(
				'recateid'=>$strCate['recateid'],
			));
			
			//条件 
			$where = array(
				'cateid2'=>$strCate['cateid'],
				'isaudit'=>0,
			);
		
		}
		
		
		//分类下课程
		$arrStudys = $new['study']->findAll('study',$where,'addtime desc',null,$lstart.',40');
		foreach($arrStudys as $key=>$item){
            $arrStudy[$key] = $item;
            $arrStudy[$key]['studyname'] = cututf8($item['studyname'],0,20,false);
			$arrStudy[$key]['user'] = aac('user')->getOneUser($item['userid']);
		}

        $studyNum = $new ['study']->findCount ( 'study', $where);

        $pageUrl = pagination ( $studyNum, 40, $page, $url );


	
		$title = $strCate['catename'];
		include template('cate');
		break;
		
		
	//二级分类	
	case "two":
		$cateid = intval($_GET['cateid']);
		
		$arrCate = $new['study']->findAll('study_cates',array(
			'recateid'=>$cateid,
		));
		
		if($arrCate){
			echo '<select id="cateid2" name="cateid2">';
			echo '<option value="0">请选择</option>';
			foreach($arrCate as $item){
				echo '<option value="'.$item['cateid'].'">'.$item['catename'].'</option>';
			}
			echo "</select>";
		}else{
			echo '';
		}
		break;
	
	//三级分类
	case "three":
		$cateid2 = intval($_GET['cateid2']);
		
		$arrCate = $new['study']->findAll('study_cates',array(
			'recateid'=>$cateid2,
		));
		
		if($arrCate){
			echo '<select id="cateid3" name="cateid3">';
			echo '<option value="0">请选择</option>';
			foreach($arrCate as $item){
				echo '<option value="'.$item['cateid'].'">'.$item['catename'].'</option>';
			}
			echo "</select>";
		}else{
			echo '';
		}
		break;

}
